package com.heng.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

@Component
public class OrderNoGenerator {

    @Value("${order.prefix}")
    private String orderPrefix;

    /**
     * 生成订单号：前缀+yyyyMMddHHmmss+6位随机数
     */
    public String generate() {
        // 时间部分：yyyyMMddHHmmss
        String timeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        // 随机数部分：6位
        String randomStr = new Random().nextInt(900000) + 100000 + "";
        // 组合订单号
        return orderPrefix + timeStr + randomStr;
    }
}